package comp.part
{
	import mx.controls.TextInput;

	import flash.display.DisplayObject;
	import flash.events.FocusEvent;
		
	public class TextInputProme extends TextInput
	{
		/**
		 *  @private
		 */
		private var _prompt:String = "";
		private var tmp:Boolean = false;
		/**
		 *  prompt 作用是用于输入框提示。
		 *  当输入框获得焦点时 清除 text的值和文本颜色，还原原来的文本颜色。
		 *  当输入框失去焦点时，判断文本是否为空，如何为空继续显示提示，否则不做任何修改。
		 *  
		 *  @ 默认""
		 *       
		 *  @langversion 3.0
		 *  @playerversion Flash 10
		 *  @playerversion AIR 1.5
		 *  @productversion Flex 4
		 */
		public function get prompt():String
		{
			return _prompt;
		}
		/**
		 *  @private
		 */
		public function set prompt(value:String):void
		{
			if (_prompt == value)
				return;
			_prompt = value;
			super.text = _prompt;
			this.setStyle("color","#A9A8A8");
			tmp = true;
		}
		
		/**
		 *  @private 当输入框获得焦点时
		 */
		override protected function focusInHandler(event:FocusEvent):void
		{
			if (event.target == this)
			{
				// call setFocus on ourselves to pass focus to the
				// textDisplay.  This situation occurs when the
				// player occasionally takes over the first TAB
				// on a newly activated Window with nothing currently
				// in focus
				setFocus();
				return;
			}
			if(tmp){
				super.text = "";
				this.setStyle("color","#000000");
				tmp = false;
			}
			// Only editable text should have a focus ring.
			if (enabled && editable && focusManager)
				focusManager.showFocusIndicator = true;
			
			super.focusInHandler(event);
		}
		
		/**
		 *  @private 当输入框失去焦点时
		 */
		override  protected function focusOutHandler(event:FocusEvent):void
		{
			if(super.text == ""){
				tmp = true;
				super.text = _prompt;
				this.setStyle("color","#A9A8A8");
			}
			// We don't need to remove our event listeners here because we
			// won't receive keyboard events.
			if (isOurFocus(DisplayObject(event.target)))
				drawFocus(false);
		}
		public function TextInputProme()
		{
			super();
		}
	}
}